//
//  MainGoodsFilterView.m
//  WeiYiMei
//
//  Created by 李叶夫 on 2019/4/11.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "MainGoodsFilterView.h"

@interface MainGoodsFilterView ()

@property (nonatomic, strong) UIButton *filterBtn1;
@property (nonatomic, strong) UIImageView *filterIcon1;

@property (nonatomic, strong) UIButton *filterBtn2;
@property (nonatomic, strong) UIImageView *filterIcon2;

@property (nonatomic, strong) UIButton *filterBtn3;
@property (nonatomic, strong) UIImageView *filterIcon3;



@end

@implementation MainGoodsFilterView

- (void)updateFilter1
{
    if (self.selectAll) {
        self.filterBtn1.selected = YES;
        self.filterIcon1.image = [UIImage imageNamed:@"h_arrowdown-1"];
    }
    else {
        self.filterBtn1.selected = NO;
        self.filterIcon1.image = [UIImage imageNamed:@"h_arrowmoren"];
    }
}

- (void)updateFilter2
{
    if (self.selectSale == kSaleNornalState) {
        self.filterBtn2.selected = NO;
        self.filterIcon2.image = [UIImage imageNamed:@"h_arrowmoren"];
    }
    if (self.selectSale == kSaleUpState) {
        self.filterBtn2.selected = YES;
        self.filterIcon2.image = [UIImage imageNamed:@"h_arrowup"];
    }
    if (self.selectSale ==kSaleDownState) {
        self.filterBtn2.selected = YES;
        self.filterIcon2.image = [UIImage imageNamed:@"h_arrowdown-1"];
    }
}

- (void)updateFilter3
{
    if (self.selectType == kTypeNormalState) {
        [self.filterBtn3 setTitle:@"商品类型" forState:UIControlStateNormal];
        self.filterBtn3.selected = NO;
        self.filterIcon3.image = [UIImage imageNamed:@"h_arrowmoren"];
    }
    else {
        [self.filterBtn3 setTitle:self.selectType forState:UIControlStateNormal];
        self.filterBtn3.selected = YES;
        self.filterIcon3.image = [UIImage imageNamed:@"h_arrowdown-1"];
    }
}


- (void)filterAction1:(id)sender
{
    if (self.allHandler) {
        self.allHandler();
    }
}

- (void)setSelectAll:(BOOL)selectAll
{
    _selectAll = selectAll;
    [self updateFilter1];
    [self updateFilter2];
    [self updateFilter3];
}

- (void)filterAction2:(id)sender
{
    if (self.saleHandler) {
        self.saleHandler();
    }
}

- (void)setSelectSale:(NSString *)selectSale
{
    _selectSale = selectSale;
    [self updateFilter1];
    [self updateFilter2];
    [self updateFilter3];
}

- (void)filterAction3:(id)sender
{
    if (self.typeHandler) {
        self.typeHandler();
    }
}

- (void)setSelectType:(NSString *)selectType
{
    _selectType = selectType;
    [self updateFilter1];
    [self updateFilter2];
    [self updateFilter3];
}


- (void)setupSubViews
{
    self.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:self.filterBtn1];
    [self.filterBtn1 setTitle:@"综合" forState:UIControlStateNormal];
    self.filterBtn1.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filterBtn1 setTitleColor:kColor777777 forState:UIControlStateNormal];
    [self.filterBtn1 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    self.filterBtn1.selected = YES;
    
    self.filterIcon1 = [[UIImageView alloc] init];
    self.filterIcon1.image = [UIImage imageNamed:@"h_arrowmoren"];
    [self addSubview:self.filterIcon1];
    
    [self addSubview:self.filterBtn2];
    [self.filterBtn2 setTitle:@"销量" forState:UIControlStateNormal];
    self.filterBtn2.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filterBtn2 setTitleColor:kColor777777 forState:UIControlStateNormal];
    [self.filterBtn2 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    self.filterBtn2.selected = NO;
    
    self.filterIcon2 = [[UIImageView alloc] init];
    self.filterIcon2.image = [UIImage imageNamed:@"h_arrowmoren"];
    [self addSubview:self.filterIcon2];
    
    [self addSubview:self.filterBtn3];
    
    self.filterBtn3.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.filterBtn3 setTitleColor:kColor777777 forState:UIControlStateNormal];
    [self.filterBtn3 setTitleColor:kColor1A75FF forState:UIControlStateSelected];
    [self.filterBtn3 setTitle:@"商品类型" forState:UIControlStateNormal];
    self.filterBtn3.selected = NO;
    
    self.filterIcon3 = [[UIImageView alloc] init];
    self.filterIcon3.image = [UIImage imageNamed:@"h_arrowmoren"];
    [self addSubview:self.filterIcon3];
    
    [self.filterBtn1 addTarget:self action:@selector(filterAction1:) forControlEvents:UIControlEventTouchUpInside];
    [self.filterBtn2 addTarget:self action:@selector(filterAction2:) forControlEvents:UIControlEventTouchUpInside];
    [self.filterBtn3 addTarget:self action:@selector(filterAction3:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)setupConstraints
{
    [self.filterBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self).offset(16);
    }];
    
    [self.filterIcon1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.filterBtn1.mas_right).offset(3);
    }];
    
    [self.filterBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.centerX.equalTo(self);
    }];
    
    [self.filterIcon2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.filterBtn2.mas_right).offset(3);
    }];
    
    [self.filterIcon3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-16);
    }];
    
    [self.filterBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.right.equalTo(self.filterIcon3.mas_left).offset(-3);
    }];
}

- (UIButton *)filterBtn1
{
    if (!_filterBtn1) {
        _filterBtn1 = [[UIButton alloc] init];
    }
    return _filterBtn1;
}

- (UIButton *)filterBtn2
{
    if (!_filterBtn2) {
        _filterBtn2 = [[UIButton alloc] init];
    }
    return _filterBtn2;
}

- (UIButton *)filterBtn3
{
    if (!_filterBtn3) {
        _filterBtn3 = [[UIButton alloc] init];
    }
    return _filterBtn3;
}

@end
